package ca.seia.comp6521.a1.sortalgorithms;

public class BubbleSort extends SortAlgorithm {
	
	
	
	public BubbleSort() {
		
		this.algorithmName = "Bubble Sort";
	}

	public void sort(int [] items){
		
		this.numberOfInnerLoops = 0; // Statistics Code
		this.numberOfOuterLoops = 0; // Statistics Code
		 
		
		int temp;
		boolean swapped;
		
	    long startTime = System.nanoTime(); // Statistics Code
		
		do {
			++(this.numberOfOuterLoops); // Statistics Code
			swapped = false;
			for ( int i =1; i < items.length; i++ )
			{
				++(this.numberOfInnerLoops); // Statistics Code
				if (items[i -1] > items[i])
				{	
					++(this.numberOfSwaps); //Statistics Code
					// Swapping Values
					temp = items[i -1];
					items[i -1] = items[i];
					items[i] = temp;
					swapped = true;
				}
			}
			
		} while (swapped == true);
		
		long endTime = System.nanoTime(); // Statistics Code
		
		this.executionTime = endTime - startTime;
		
		
		
	}
	
	
	
}
